package fr.webeo.teambuilder.gui;

import java.awt.Component;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * The class <strong>MyCellRenderer</strong>.
 * 
 * @author Sébastien Bordes
 * @version $Revision$ $Date$ $Name$
 * 
 * @since fr.webeo.teambuilder 1.0
 */
public class MyCellRenderer extends DefaultTableCellRenderer {

    /**
	 * 
	 */
    public MyCellRenderer() {
    }

    /**
	 * 
	 */
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        if (value instanceof Boolean) {
            JCheckBox cb = new JCheckBox();
            cb.setSelected(((Boolean) value).booleanValue());
            cb.setHorizontalAlignment(0);
            if (isSelected) {
                cb.setForeground(table.getSelectionForeground());
                cb.setBackground(table.getSelectionBackground());
            } else {
                cb.setForeground(table.getForeground());
                cb.setBackground(table.getBackground());
            }
            return cb;
        }
        JLabel l = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (value instanceof Date) {
            SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy \340 HH:mm:ss");
            l.setText(sdf.format((Date) value));
        }
        l.setHorizontalAlignment(0);
        return l;
    }
}
